<?php
defined("IN_IA") or exit("Access Denied");
class yzzc_sunModuleWxapp extends WeModuleWxapp
{
    public function doPageUrl()
    {
        global $_W;
        $url = $_W["attachurl"];
        $this->return_msg(1, $url, "success");
    }
    function return_msg($code = 1, $data = array(), $msg = "success")
    {
        $res["code"] = $code;
        $res["data"] = $data;
        $res["msg"] = $msg;
        exit(json_encode($res));
    }
    function scoreAct($uid, $type = 1, $score = 0)
    {
        global $_W;
        $data["uniacid"] = $_W["uniacid"];
        $data["uid"] = $uid;
        $data["type"] = $type;
        $data["score"] = $score;
        $data["createtime"] = time();
        pdo_insert("yzzc_sun_integral_log", $data);
        if ($score > 0) {
            pdo_update("yzzc_sun_user", array("all_integral +=" => $data["score"]), array("id" => $data["uid"]));
        }
        pdo_update("yzzc_sun_user", array("now_integral +=" => $data["score"]), array("id" => $data["uid"]));
    }
    public function wxPay($options = array())
    {
        $data["appid"] = $options["appid"];
        $data["mch_id"] = $options["mch_id"];
        $data["openid"] = $options["openid"];
        $data["nonce_str"] = $this->randstr();
        $data["body"] = $options["body"];
        $data["attach"] = $options["attach"];
        $data["out_trade_no"] = $options["out_trade_no"];
        $data["notify_url"] = $options["notify_url"];
        $data["total_fee"] = $options["total_fee"] * 100;
        $data["spbill_create_ip"] = $_SERVER["REMOTE_ADDR"];
        $data["trade_type"] = "JSAPI";
        $data["time_start"] = $options["time_start"];
        $data["time_expire"] = $options["time_expire"];
        ksort($data, SORT_STRING);
        $string = '';
        foreach ($data as $key => $v) {
            if (!empty($v)) {
                $string .= "{$key}={$v}&";
            } else {
            }
        }
        $string .= "key=" . $options["pay_key"] . '';
        $data["sign"] = strtoupper(md5($string));
        $xmlData = array2xml($data);
        $response = $this->https_request("https://api.mch.weixin.qq.com/pay/unifiedorder", $xmlData);
        $result = json_decode(json_encode(simplexml_load_string($response, "SimpleXMLElement", LIBXML_NOCDATA)), true);
        if ($result["return_code"] == "SUCCESS") {
            $payData["appId"] = $data["appid"];
            $payData["timeStamp"] = (string) time();
            $payData["nonceStr"] = $this->randstr();
            $payData["package"] = "prepay_id=" . $result["prepay_id"];
            $payData["signType"] = "MD5";
            $payString = '';
            ksort($payData, SORT_STRING);
            foreach ($payData as $key => $v) {
                $payString .= "{$key}={$v}&";
            }
            $payString .= "key=" . $options["pay_key"] . '';
            $payData["paySign"] = strtoupper(md5($payString));
            $payData["return_code"] = $result["return_code"];
        } else {
            $payData["return_code"] = $result["return_code"];
            $payData["return_msg"] = $result["return_msg"];
        }
        return $payData;
    }
    public function testpay()
    {
        $appid = '';
        $mch_id = '';
        $options = array("body" => "测试", "appid" => $appid, "mch_id" => $mch_id, "out_trade_no" => time(), "attach" => json_encode(array("a" => 1)), "notify_url" => "http://" . $_SERVER["HTTP_HOST"] . "/ticket/Appletpay/notify", "total_fee" => 0.01, "spbill_create_ip" => $_SERVER["REMOTE_ADDR"], "openid" => "oLWoc0X0guzZ89lxWdL57Z7mz4r4");
        $data = $this->wxPay($options);
        return common_json("success", 0, $data);
    }
    public function notify()
    {
        $json = $_POST;
        $xml = file_get_contents("php://input");
        $data = json_decode(json_encode(simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA)), true);
        $arraySign = $data["sign"];
        unset($data["sign"]);
        ksort($data, SORT_STRING);
        $string = '';
        foreach ($data as $key => $v) {
            $string .= "{$key}={$v}&";
        }
        $arr = json_decode($data["attach"], true);
        $pay_key = '';
        $string .= "key=" . $pay_key;
        $sign = strtoupper(md5($string));
        if ($arraySign == $sign) {
            exit("SUCCESS");
        } else {
            exit("FAIL");
        }
    }
    function randstr($length = 20)
    {
        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $str = '';
        $i = 0;
        while ($i < $length) {
            $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
            $i++;
        }
        return $str;
    }
    function https_request($url, $data = null)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($curl, CURLOPT_SSLVERSION, 4);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    public function doPageOpenid()
    {
        global $_W, $_GPC;
        $res = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]));
        $code = $_GPC["code"];
        $appid = $res["appid"];
        $secret = $res["appsecret"];
        $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
        function httpRequest($url, $data = null)
        {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
            if (!empty($data)) {
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            }
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            $output = curl_exec($curl);
            curl_close($curl);
            return $output;
        }
        $re = httpRequest($url);
        $opendata = json_decode($re);
        $openid = $opendata->openid;
        $res = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
        if ($res) {
            $res["session_key"] = $opendata->session_key;
            $this->return_msg(1, $res, "success");
        } else {
            $data = array();
            $data["openid"] = $openid;
            $data["user_name"] = "访客" . rand(10000, 99999);
            $data["uniacid"] = $_W["uniacid"];
            $data["time"] = time();
            $res2 = pdo_insert("yzzc_sun_user", $data);
            $user = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
            $user["session_key"] = $opendata->session_key;
            $this->return_msg(1, $user, "success");
        }
    }
    public function doPageLoginOpenid()
    {
        global $_W, $_GPC;
        $res = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]));
        $code = $_GPC["code"];
        $appid = $res["appid"];
        $secret = $res["appsecret"];
        $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
        function httpRequest($url, $data = null)
        {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
            if (!empty($data)) {
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            }
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            $output = curl_exec($curl);
            curl_close($curl);
            return $output;
        }
        $re = httpRequest($url);
        $opendata = json_decode($re);
        $openid = $opendata->openid;
        $res = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
        if ($res) {
            $res["session_key"] = $opendata->session_key;
            $this->return_msg(1, $res, "success");
        } else {
            $data = array();
            $data["openid"] = $openid;
            $data["user_name"] = "访客" . rand(10000, 99999);
            $data["uniacid"] = $_W["uniacid"];
            $data["time"] = time();
            $res2 = pdo_insert("yzzc_sun_user", $data);
            $user = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
            $user["session_key"] = $opendata->session_key;
            $this->return_msg(1, $user, "success");
        }
    }
    public function doPageLogin()
    {
        global $_GPC, $_W;
        $openid = $_GPC["openid"];
        $res = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
        if ($openid and $openid != "undefined") {
            if ($res) {
                $data["openid"] = $_GPC["openid"];
                $data["headimg"] = $_GPC["headimg"];
                $data["user_name"] = $_GPC["user_name"];
                $res1 = pdo_update("yzzc_sun_user", $data, array("openid" => $openid, "uniacid" => $_W["uniacid"]));
                $user = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
                $this->return_msg(1, $user);
            } else {
                $data["openid"] = $_GPC["openid"];
                $data["headimg"] = $_GPC["headimg"];
                $data["user_name"] = $_GPC["user_name"];
                $data["uniacid"] = $_W["uniacid"];
                $data["time"] = time();
                pdo_insert("yzzc_sun_user", $data);
                $user = pdo_get("yzzc_sun_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
                $this->return_msg(1, $user);
            }
        }
    }
    public function doPageShouye()
    {
        global $_GPC, $_W;
        $guoqi = pdo_getall("yzzc_sun_xzorder", array("uniacid" => $_W["uniacid"], "ispay" => 0));
        foreach ($guoqi as $key => $value) {
            if ($value["createtime"] + 500 < time()) {
                $guoqi1 = pdo_delete("yzzc_sun_xzorder", array("uniacid" => $_W["uniacid"], "id" => $value["id"]));
            }
        }
        $banner = pdo_get("yzzc_sun_banner", array("uniacid" => $_W["uniacid"]), array("lb_imgs"));
        $res["banner"] = explode(",", $banner["lb_imgs"]);
        $res["icon"] = pdo_get("yzzc_sun_logoset", array("uniacid" => $_W["uniacid"]));
        $res["index_haibao_pic"] = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), array("index_haibao_pic"));
        $system = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), array("is_open_car", "open_ys"));
        $res["is_open_car"] = $system["is_open_car"];
        $res["open_ys"] = $system["open_ys"];
        $filed = array("id", "pic", "moneytype", "money", "name");
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        if ($system["open_ys"] == 1) {
            if ($_GPC["state"] == 1) {
                if ($_GPC["sort"] == "distance") {
                    $start = ($page - 1) * $length;
                    $lat = $_GPC["lat"] ? $_GPC["lat"] : 0;
                    $lng = $_GPC["lng"] ? $_GPC["lng"] : 0;
                    if ($lat > 0 && $lng > 0) {
                        $sql = "select a.id,a.pic,b.lng,b.lat,a.moneytype,a.money,a.name,( 6371 * acos (    \n                        cos ( radians(" . $lat . ") )    \n                        * cos( radians( b.lat ) )    \n                        * cos( radians( b.lng ) - radians(" . $lng . ") )    \n                        + sin ( radians(" . $lat . ") )    \n                        * sin( radians( b.lat ) )    )    \n                        ) AS distance from " . tablename("yzzc_sun_goods") . "a " . "left join" . tablename("yzzc_sun_branch") . "b on b.id=a.sid \n                    where a.rec =1 and a.status =1 and a.is_del = 0 and b.status = 1 and a.uniacid = " . $_W["uniacid"] . " order by distance asc,a.id desc limit " . $start . "," . $length;
                        $list = pdo_fetchall($sql);
                        $res["car"] = $list;
                    } else {
                        $this->return_msg(-1, array(), "请先定位");
                    }
                } else {
                    $res["car"] = pdo_getall("yzzc_sun_goods", array("uniacid" => $_W["uniacid"], "status" => 1, "rec" => 1, "is_del" => 0), $filed, '', "id desc", array($page, $length));
                }
            } else {
                $start = ($page - 1) * $length;
                $res["car"] = pdo_fetchall("select * from " . tablename("yzzc_sun_car") . " where uniacid =" . $_W["uniacid"] . " and status = 2 and rec = 1 and is_del = 0 order by sort asc limit " . $start . "," . $length);
            }
        } else {
            $start = ($page - 1) * $length;
            if ($_GPC["sort"] == "distance") {
                $lat = $_GPC["lat"] ? $_GPC["lat"] : 0;
                $lng = $_GPC["lng"] ? $_GPC["lng"] : 0;
                if ($lat > 0 && $lng > 0) {
                    $sql = "select a.id,a.pic,b.lng,b.lat,a.moneytype,a.money,a.name,( 6371 * acos (    \n                    cos ( radians(" . $lat . ") )    \n                    * cos( radians( b.lat ) )    \n                    * cos( radians( b.lng ) - radians(" . $lng . ") )    \n                    + sin ( radians(" . $lat . ") )    \n                    * sin( radians( b.lat ) )    )    \n                    ) AS distance from " . tablename("yzzc_sun_goods") . "a " . "left join" . tablename("yzzc_sun_branch") . "b on b.id=a.sid \n                where a.rec =1 and a.status =1 and a.is_del = 0 and b.status = 1 and a.uniacid = " . $_W["uniacid"] . " order by distance asc,a.id desc limit " . $start . "," . $length;
                    $list = pdo_fetchall($sql);
                    $res["car"] = $list;
                } else {
                    $this->return_msg(-1, array(), "请先定位");
                }
            } else {
                $res["car"] = pdo_getall("yzzc_sun_goods", array("uniacid" => $_W["uniacid"], "status" => 1, "rec" => 1, "is_del" => 0), $filed, '', "id desc", array($page, $length));
            }
            $res["ershoucar"] = pdo_fetchall("select * from " . tablename("yzzc_sun_car") . " where uniacid =" . $_W["uniacid"] . " and status = 2 and rec = 1 and is_del = 0 order by sort asc limit " . $start . "," . $length);
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPagegetcity()
    {
        global $_GPC, $_W;
        $city_id = $_GPC["city_id"];
        $uid = $_GPC["uid"];
        if ($city_id) {
            $nowcity = pdo_get("yzzc_sun_carcity", array("uniacid" => $_W["uniacid"], "id" => $city_id));
            $res["nowcity"] = $nowcity;
        }
        $reccity = pdo_getall("yzzc_sun_carcity", array("uniacid" => $_W["uniacid"], "rec" => 1), array(), '', "zimu asc");
        $res["reccity"] = $reccity;
        $usercity = pdo_fetchall("select a.name,a.id from " . tablename("yzzc_sun_carcity") . "a left join " . tablename("yzzc_sun_usercity") . "b on b.city_id = a.id where b.uid = {$uid} and a.uniacid = " . $_W["uniacid"] . " and b.uniacid = " . $_W["uniacid"] . " order by b.time desc");
        $res["usercity"] = $usercity;
        $city = pdo_getall("yzzc_sun_carcity", array("uniacid" => $_W["uniacid"]), array(), '', "zimu asc");
        $city = $this->dataGroup($city, "zimu");
        $res["city"] = $city;
        $this->return_msg(1, $res, "success");
    }
    public function doPagegetbrand()
    {
        global $_GPC, $_W;
        $brand_id = $_GPC["brand_id"];
        if ($brand_id) {
            $nowbrand = pdo_get("yzzc_sun_carbrand", array("uniacid" => $_W["uniacid"], "id" => $brand_id));
            $res["nowbrand"] = $nowbrand;
        }
        $brand = pdo_getall("yzzc_sun_carbrand", array("uniacid" => $_W["uniacid"]), array(), '', "zimu asc");
        $brand = $this->dataGroup($brand, "zimu");
        $res["brand"] = $brand;
        $this->return_msg(1, $res, "success");
    }
    public function dataGroup($dataArr, $keyStr)
    {
        $newArr = [];
        foreach ($dataArr as $k => $val) {
            $newArr[$val[$keyStr]][] = $val;
        }
        return $newArr;
    }
    public function doPagechoosecity()
    {
        global $_GPC, $_W;
        $uid = $_GPC["uid"];
        $city_id = $_GPC["city_id"];
        $res = pdo_get("yzzc_sun_usercity", array("uniacid" => $_W["uniacid"], "uid" => $uid, "city_id" => $city_id));
        if ($res) {
            $data["time"] = time();
            $result = pdo_update("yzzc_sun_usercity", $data, array("uniacid" => $_W["uniacid"], "id" => $res["id"]));
        } else {
            $city = pdo_getall("yzzc_sun_usercity", array("uniacid" => $_W["uniacid"], "uid" => $uid), array(), '', "time asc");
            if (count($city) < 3) {
                $data["uid"] = $uid;
                $data["city_id"] = $city_id;
                $data["uniacid"] = $_W["uniacid"];
                $data["time"] = time();
                $result = pdo_insert("yzzc_sun_usercity", $data);
            } else {
                pdo_delete("yzzc_sun_usercity", array("uniacid" => $_W["uniacid"], "id" => $city["0"]["id"]));
                $data["uid"] = $uid;
                $data["city_id"] = $city_id;
                $data["uniacid"] = $_W["uniacid"];
                $data["time"] = time();
                $result = pdo_insert("yzzc_sun_usercity", $data);
            }
        }
    }
    public function doPageuserdcarlist()
    {
        global $_GPC, $_W;
        $where = " where uniacid = " . $_W["uniacid"] . " and status = 2 and is_del = 0 ";
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $start = ($page - 1) * $length;
        $limit = "limit " . $start . "," . $length;
        $sort = $_GPC["sort"];
        $city_id = $_GPC["city_id"];
        if ($city_id != 0) {
            $where .= " and carcity = " . $city_id;
        }
        $brand_id = $_GPC["brand_id"];
        if ($brand_id != 0) {
            $where .= " and carbrand = " . $brand_id;
        }
        $carnum = $_GPC["carnum"];
        if ($carnum) {
            $where .= " and carnum like '%{$carnum}%'";
        }
        if ($sort == 1) {
            $order = " order by sort asc ";
        } else {
            if ($sort == 2) {
                $order = " order by money desc ";
            } else {
                if ($sort == 3) {
                    $order = " order by money asc ";
                } else {
                    if ($sort == 4) {
                        $order = " order by registrationtime desc ";
                    } else {
                        if ($sort == 5) {
                            $order = " order by mileage asc ";
                        } else {
                        }
                    }
                }
            }
        }
        $res = pdo_fetchall("select * from " . tablename("yzzc_sun_car") . $where . $order . $limit);
        foreach ($res as $key => $value) {
            $res[$key]["registrationtime"] = date("Y年m月", $value["registrationtime"]);
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPageuserdcar()
    {
        global $_GPC, $_W;
        $id = $_GPC["id"];
        $res = pdo_get("yzzc_sun_car", array("uniacid" => $_W["uniacid"], "id" => $id, "status" => 2, "is_del" => 0));
        $res["registrationtime"] = date("Y年m月", $res["registrationtime"]);
        $res["carcity"] = pdo_get("yzzc_sun_carcity", array("uniacid" => $_W["uniacid"], "id" => $res["carcity"]), array("name"))["name"];
        $res["imgs"] = explode(",", $res["imgs"]);
        $this->return_msg(1, $res, "success");
    }
    public function rec()
    {
        global $_GPC, $_W;
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $start = ($page - 1) * $length;
        $lat = $_GPC["lat"] ? $_GPC["lat"] : 0;
        $lng = $_GPC["lng"] ? $_GPC["lng"] : 0;
        if ($lat > 0 && $lng > 0) {
            $sql = "select a.id,a.pic,b.lng,b.lat,a.moneytype,a.money,a.name,( 6371 * acos (    \n                cos ( radians(" . $lat . ") )    \n                * cos( radians( b.lat ) )    \n                * cos( radians( b.lng ) - radians(" . $lng . ") )    \n                + sin ( radians(" . $lat . ") )    \n                * sin( radians( b.lat ) )    )    \n                ) AS distance from " . tablename("yzzc_sun_goods") . "a " . "left join" . tablename("yzzc_sun_branch") . "b on b.id=a.sid \n            where a.rec =1 and a.status =1 and a.is_del = 0 and b.status = 1 and a.uniacid = " . $_W["uniacid"] . " order by distance asc limit " . $start . "," . $length;
            $list = pdo_fetchall($sql);
            var_dump($list);
            exit;
        } else {
            $this->return_msg(-1, array(), "请先定位");
        }
    }
    public function doPageuserdrive()
    {
        global $_W, $_GPC;
        $uid = $_GPC["uid"];
        $sql = "SELECT * FROM " . tablename("yzzc_sun_user_drive") . " where uid = " . $uid . " ORDER BY id DESC";
        $res = pdo_fetchall($sql);
        $this->return_msg(1, $res, "success");
    }
    public function doPageuserdriveset()
    {
        global $_W, $_GPC;
        $set = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("zj"));
        $zj = explode(",", $set["zj"]);
        $sfcode = 0;
        $sfimg = 0;
        $jsimg = 0;
        $zpimg = 0;
        if (in_array("0", $zj)) {
            $sfcode = 1;
        }
        if (in_array("1", $zj)) {
            $sfimg = 1;
        }
        if (in_array("2", $zj)) {
            $jsimg = 1;
        }
        if (in_array("3", $zj)) {
            $zpimg = 1;
        }
        $info = array("sfcode" => $sfcode, "sfimg" => $sfimg, "jsimg" => $jsimg, "zpimg" => $zpimg);
        $this->return_msg(1, $info, "success");
    }
    public function doPageEdituserdriveInfo()
    {
        global $_GPC, $_W;
        $info = pdo_get("yzzc_sun_user_drive", array("uniacid" => $_W["uniacid"], "id" => $_GPC["id"]));
        $this->return_msg(1, $info, "success");
    }
    public function doPageEdituserdrive()
    {
        global $_W, $_GPC;
        $set = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]));
        $zj = explode(",", $set["zj"]);
        $data["uid"] = $_GPC["uid"];
        $data["name"] = $_GPC["name"];
        $data["phone"] = $_GPC["phone"];
        if (in_array("0", $zj)) {
            if (empty($_GPC["sfcode"])) {
                $this->return_msg(-1, array(), "请输入驾驶员身份证号码");
            }
            $data["sfcode"] = $_GPC["sfcode"];
        }
        if (in_array("1", $zj)) {
            if (empty($_GPC["sfimg"]) || empty($_GPC["sfimgfan"])) {
                $this->return_msg(-1, array(), "请上传身份证正反面照片");
            }
            $data["sfimg"] = $_GPC["sfimg"];
            $data["sfimgfan"] = $_GPC["sfimgfan"];
        }
        if (in_array("2", $zj)) {
            if (empty($_GPC["jsimg"]) || empty($_GPC["jsimgfan"])) {
                $this->return_msg(-1, array(), "请上传驾驶证正面和附页照片");
            }
            $data["jsimg"] = $_GPC["jsimg"];
            $data["jsimgfan"] = $_GPC["jsimgfan"];
        }
        if (in_array("3", $zj)) {
            if (empty($_GPC["zpimg"])) {
                $this->return_msg(-1, array(), "请上传手持身份证自拍照片");
            }
            $data["zpimg"] = $_GPC["zpimg"];
        }
        $data["time"] = time();
        $data["uniacid"] = $_W["uniacid"];
        $res = pdo_update("yzzc_sun_user_drive", $data, array("uniacid" => $_W["uniacid"], "id" => $_GPC["driveid"]));
        if ($res) {
            $this->return_msg(1, array(), "success");
        } else {
            $this->return_msg(-1, array(), "添加失败！");
        }
    }
    public function doPageAdduserdrive()
    {
        global $_W, $_GPC;
        $set = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]));
        $zj = explode(",", $set["zj"]);
        $data["uid"] = $_GPC["uid"];
        $data["name"] = $_GPC["name"];
        $data["phone"] = $_GPC["phone"];
        if (in_array("0", $zj)) {
            if (empty($_GPC["sfcode"])) {
                $this->return_msg(-1, array(), "请输入驾驶员身份证号码");
            }
            $data["sfcode"] = $_GPC["sfcode"];
        }
        if (in_array("1", $zj)) {
            if (empty($_GPC["sfimg"]) || empty($_GPC["sfimgfan"])) {
                $this->return_msg(-1, array(), "请上传身份证正反面照片");
            }
            $data["sfimg"] = $_GPC["sfimg"];
            $data["sfimgfan"] = $_GPC["sfimgfan"];
        }
        if (in_array("2", $zj)) {
            if (empty($_GPC["jsimg"]) || empty($_GPC["jsimgfan"])) {
                $this->return_msg(-1, array(), "请上传驾驶证正面和附页照片");
            }
            $data["jsimg"] = $_GPC["jsimg"];
            $data["jsimgfan"] = $_GPC["jsimgfan"];
        }
        if (in_array("3", $zj)) {
            if (empty($_GPC["zpimg"])) {
                $this->return_msg(-1, array(), "请上传手持身份证自拍照片");
            }
            $data["zpimg"] = $_GPC["zpimg"];
        }
        $data["time"] = time();
        $data["uniacid"] = $_W["uniacid"];
        $res = pdo_insert("yzzc_sun_user_drive", $data);
        if ($res) {
            $this->return_msg(1, array(), "success");
        } else {
            $this->return_msg(-1, array(), "添加失败！");
        }
    }
    public function doPagechoosedrive()
    {
        global $_W, $_GPC;
        $id = $_GPC["id"];
        $uid = $_GPC["uid"];
        pdo_update("yzzc_sun_user_drive", array("is_mr" => 0), array("uniacid" => $_W["uniacid"], "uid" => $uid));
        $res = pdo_update("yzzc_sun_user_drive", array("is_mr" => 1), array("uniacid" => $_W["uniacid"], "id" => $id));
        if ($res) {
            $this->return_msg(1, array(), "设置成功");
        } else {
            $this->return_msg(-1, array(), "设置失败");
        }
    }
    public function doPagedeluserdrive()
    {
        global $_W, $_GPC;
        $id = $_GPC["id"];
        $info = pdo_get("yzzc_sun_user_drive", array("uniacid" => $_W["uniacid"], "id" => $_GPC["id"]));
        $res = pdo_delete("yzzc_sun_user_drive", array("uniacid" => $_W["uniacid"], "id" => $id));
        if ($res) {
            if ($info["sfimg"]) {
                unlink("../attachment/" . $info["sfimg"]);
            }
            if ($info["jsimg"]) {
                unlink("../attachment/" . $info["jsimg"]);
            }
            if ($info["sfimgfan"]) {
                unlink("../attachment/" . $info["sfimgfan"]);
            }
            if ($info["jsimgfan"]) {
                unlink("../attachment/" . $info["jsimgfan"]);
            }
            if ($info["zpimg"]) {
                unlink("../attachment/" . $info["zpimg"]);
            }
            $this->return_msg(1, array(), "删除成功");
        } else {
            $this->return_msg(-1, array(), "删除失败");
        }
    }
    public function doPageToupload()
    {
        $uptypes = array("image/jpg", "image/jpeg", "image/png", "image/pjpeg", "image/gif", "image/bmp", "image/x-png");
        $max_file_size = 4000000;
        $destination_folder = "../attachment/";
        $watermark = 2;
        $watertype = 1;
        $waterposition = 1;
        $waterstring = "666666";
        $imgpreview = 1;
        $imgpreviewsize = 1 / 2;
        if (!is_uploaded_file($_FILES["file"]["tmp_name"])) {
            echo "图片不存在!";
            exit;
        }
        $file = $_FILES["file"];
        if ($max_file_size < $file["size"]) {
            echo "文件太大!";
            exit;
        }
        if (!in_array($file["type"], $uptypes)) {
            echo "文件类型不符!" . $file["type"];
            exit;
        }
        if (!file_exists($destination_folder)) {
            mkdir($destination_folder);
        }
        $filename = $file["tmp_name"];
        $image_size = getimagesize($filename);
        $pinfo = pathinfo($file["name"]);
        $ftype = $pinfo["extension"];
        $destination = $destination_folder . str_shuffle(rand(11111, 99999) . time() . rand(111111, 999999)) . "." . $ftype;
        if (file_exists($destination) && $overwrite != true) {
            echo "同名文件已经存在了";
            exit;
        }
        if (!move_uploaded_file($filename, $destination)) {
            echo "移动文件出错";
            exit;
        }
        $pinfo = pathinfo($destination);
        $fname = $pinfo["basename"];
        if ($watermark == 1) {
            $iinfo = getimagesize($destination, $iinfo);
            $nimage = imagecreatetruecolor($image_size[0], $image_size[1]);
            $white = imagecolorallocate($nimage, 255, 255, 255);
            $black = imagecolorallocate($nimage, 0, 0, 0);
            $red = imagecolorallocate($nimage, 255, 0, 0);
            imagefill($nimage, 0, 0, $white);
            switch ($iinfo[2]) {
                case 1:
                    $simage = imagecreatefromgif($destination);
                    break;
                case 2:
                    $simage = imagecreatefromjpeg($destination);
                    break;
                case 3:
                    $simage = imagecreatefrompng($destination);
                    break;
                case 6:
                    $simage = imagecreatefromwbmp($destination);
                    break;
                default:
                    die("不支持的文件类型");
            }
            imagecopy($nimage, $simage, 0, 0, 0, 0, $image_size[0], $image_size[1]);
            imagefilledrectangle($nimage, 1, $image_size[1] - 15, 80, $image_size[1], $white);
            switch ($watertype) {
                case 1:
                    imagestring($nimage, 2, 3, $image_size[1] - 15, $waterstring, $black);
                    break;
                case 2:
                    $simage1 = imagecreatefromgif("xplore.gif");
                    imagecopy($nimage, $simage1, 0, 0, 0, 0, 85, 15);
                    imagedestroy($simage1);
                    break;
            }
            switch ($iinfo[2]) {
                case 1:
                    imagejpeg($nimage, $destination);
                    break;
                case 2:
                    imagejpeg($nimage, $destination);
                    break;
                case 3:
                    imagepng($nimage, $destination);
                    break;
                case 6:
                    imagewbmp($nimage, $destination);
                    break;
            }
            imagedestroy($nimage);
            imagedestroy($simage);
        }
        echo $fname;
        @(require_once IA_ROOT . "/framework/function/file.func.php");
        @($filename = $fname);
        @file_remote_upload($filename);
    }
    public function doPageNavset()
    {
        global $_W;
        $res = pdo_get("yzzc_sun_logoset", array("uniacid" => $_W["uniacid"]));
        $this->return_msg(1, $res, "success");
    }
    public function doPageSupport()
    {
        global $_W;
        $field = array("sup_logo", "sup_name", "sup_tel");
        $res = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), $field);
        $this->return_msg(1, $res, "success");
    }
    public function doPageColor()
    {
        global $_W;
        $field = array("top_font_color", "top_color", "foot_color", "foot_font_color_one", "foot_font_color_two", "open_fj");
        $res = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), $field);
        $this->return_msg(1, $res, "success");
    }
    public function doPageAdpic()
    {
        global $_W;
        $res = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), "ad_pic");
        if ($res["ad_pic"] == 1) {
            $res = pdo_getall("yzzc_sun_adpic", array("uniacid" => $_W["uniacid"]), array(), '', array("sort asc"));
        } else {
            $res = array();
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPageSign()
    {
        global $_GPC, $_W;
        if (empty($_GPC["uid"])) {
            $this->return_msg(-999, array(), "uid不能为空");
        } else {
            $today = strtotime(date("Y-m-d", time()));
            $issign = pdo_get("yzzc_sun_signlog", array("uid" => $_GPC["uid"], "createtime >=" => $today));
            if ($issign) {
                $this->return_msg(-1, array(), "今天已经签到了哦");
            }
            $integral = pdo_get("yzzc_sun_integralset", array("uniacid" => $_W["uniacid"]), array("sign"));
            if ($integral["sign"] > 0) {
                $this->scoreAct($_GPC["uid"], 1, $integral["sign"]);
            }
            $data["uniacid"] = $_W["uniacid"];
            $data["uid"] = $_GPC["uid"];
            $data["score"] = $integral["sign"];
            $data["createtime"] = time();
            $res = pdo_insert("yzzc_sun_signlog", $data);
            if ($res) {
                $this->return_msg(1, array("score" => $data["score"]), "签到成功");
            } else {
                $this->return_msg(-1, array(), "签到失败");
            }
        }
    }
    public function doPageUsers()
    {
        global $_GPC, $_W;
        if ($_GPC["uid"]) {
            $res["user"] = pdo_get("yzzc_sun_user", array("uniacid" => $_W["uniacid"], "id" => $_GPC["uid"]));
            $res["mylevel"] = $this->mylevel($res["user"]["all_integral"]);
            $res["couponnum"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_coupon_get") . "where uid =" . $_GPC["uid"] . " and type = 2 and isuse = 0");
            $res["rentnum"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_coupon_get") . "where uid =" . $_GPC["uid"] . " and type = 1 ");
            $this->return_msg(1, $res);
        }
    }
    public function doPageHelps()
    {
        global $_W;
        $res = pdo_get("yzzc_sun_new", array("uniacid" => $_W["uniacid"]));
        $this->return_msg(1, $res);
    }
    public function doPageRule()
    {
        global $_W;
        $res["rule"] = pdo_getall("yzzc_sun_rule", array("uniacid" => $_W["uniacid"]));
        $res["img"] = pdo_get("yzzc_sun_banner", array("uniacid" => $_W["uniacid"]), array("rules_banner"))["rules_banner"];
        $this->return_msg(1, $res);
    }
    public function doPageWe()
    {
        global $_W;
        $res = pdo_get("yzzc_sun_we", array("uniacid" => $_W["uniacid"]));
        $this->return_msg(1, $res);
    }
    public function doPageVio()
    {
        global $_W;
        $banner = pdo_getall("wyzc_sun_violation", array("uniacid" => $_W["uniacid"], "states" => 2));
        echo json_encode($banner);
    }
    public function doPageTaocan()
    {
        global $_W;
        $res = pdo_getall("yzzc_sun_taocan", array("uniacid" => $_W["uniacid"], "status" => 1), array("id", "name", "day", "money"), '', "id desc");
        $this->return_msg(1, $res);
    }
    public function doPageActive()
    {
        global $_GPC, $_W;
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $active = pdo_getall("yzzc_sun_active", array("uniacid" => $_W["uniacid"], "status" => 1), array(), '', "createtime desc", array($page, $length));
        foreach ($active as $key => $value) {
            if ($value["acttime"]) {
                $active[$key]["acttime"] = date("Y-m-d H:i:s", $value["acttime"]);
            }
        }
        $this->return_msg(1, $active);
    }
    public function doPageActiveInfo()
    {
        global $_GPC, $_W;
        $active = pdo_get("yzzc_sun_active", array("uniacid" => $_W["uniacid"], "aid" => $_GPC["aid"], "status" => 1));
        if ($active) {
            $this->return_msg(1, $active);
        } else {
            $this->return_msg(-1, array(), "活动不存在");
        }
    }
    public function doPageCouponList()
    {
        global $_GPC, $_W;
        $filed = array("id", "start_time", "end_time", "money", "full", "limit");
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $res = pdo_getall("yzzc_sun_coupon", array("uniacid" => $_W["uniacid"], "status" => 1, "type" => 2, "end_time >" => time()), $filed, '', array("id desc"), array($page, $length));
        foreach ($res as $key => $value) {
            $isget = pdo_get("yzzc_sun_coupon_get", array("cid" => $value["id"], "uid" => $_GPC["uid"]));
            if ($isget) {
                $res[$key]["isget"] = 1;
            } else {
                $res[$key]["isget"] = 0;
            }
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPageGetCoupon()
    {
        global $_GPC, $_W;
        if (empty($_GPC["uid"])) {
            $this->return_msg(-999, array(), "请先登录");
        }
        $uid = $_GPC["uid"];
        $sql = "select id from" . tablename("yzzc_sun_coupon_get") . "where cid=" . $_GPC["cid"] . " and uid=" . "'{$uid}'";
        $isget = pdo_fetch($sql);
        if ($isget) {
            $this->return_msg(-1, array(), "您已领过");
        }
        $info = pdo_get("yzzc_sun_coupon", array("uniacid" => $_W["uniacid"], "id" => $_GPC["cid"]));
        if ($info["end_time"] > time()) {
            if ($info["total"] == 0 || $info["total"] > $info["getnum"]) {
                $data["uid"] = $_GPC["uid"];
                $data["cid"] = $_GPC["cid"];
                $data["createtime"] = time();
                $data["uniacid"] = $_W["uniacid"];
                $data["type"] = 2;
                $res = pdo_insert("yzzc_sun_coupon_get", $data);
                pdo_update("yzzc_sun_coupon", array("getnum +=" => 1), array("id" => $_GPC["cid"]));
                if ($res) {
                    $this->return_msg(1, array(), "领取成功");
                } else {
                    $this->return_msg(-1, array(), "领取失败");
                }
            } else {
                $this->return_msg(-1, array(), "来晚了，优惠券已领完");
            }
        } else {
            $this->return_msg(-1, array(), "优惠券已过期");
        }
    }
    public function doPageMycoupon()
    {
        global $_GPC, $_W;
        if ($_GPC["type"] == 1) {
            $where = " WHERE  a.uniacid=" . $_W["uniacid"] . " and a.end_time >" . time() . "  and b.isuse = 0 ";
        } else {
            $where = " WHERE  a.uniacid=" . $_W["uniacid"] . " and a.end_time <" . time() . " and b.isuse = 0 ";
        }
        $where .= " and a.type =" . $_GPC["ctype"];
        if (empty($_GPC["uid"])) {
            $this->return_msg(-999, array(), "请先登录");
        }
        $uid = $_GPC["uid"];
        $sql = "select a.id,a.start_time,a.end_time,a.money,a.full,a.limit,b.usetime,b.createtime,b.isuse  from " . tablename("yzzc_sun_coupon") . "a " . "left join" . tablename("yzzc_sun_coupon_get") . "b on b.cid=a.id and b.uid= " . "{$uid}.{$where}";
        $mycoupon = pdo_fetchall($sql);
        $this->return_msg(1, $mycoupon);
    }
    public function doPageIntegral()
    {
        global $_GPC, $_W;
        if (empty($_GPC["uid"])) {
            $this->return_msg(-999, array(), "请先登录");
        }
        $res["user"] = pdo_get("yzzc_sun_user", array("id" => $_GPC["uid"]), array("all_integral", "now_integral"));
        $res["rentrule"] = pdo_get("yzzc_sun_allrule", array("type" => 1, "uniacid" => $_W["uniacid"]), array("content"));
        $res["rent"] = pdo_getall("yzzc_sun_coupon", array("type" => 1, "uniacid" => $_W["uniacid"], "end_time >=" => time(), "status" => 1), array("id", "score", "money", "full"));
        $res["jfrule"] = pdo_get("yzzc_sun_integralset", array("uniacid" => $_W["uniacid"]), array("rule"));
        $this->return_msg(1, $res);
    }
    public function doPageExchange()
    {
        global $_GPC, $_W;
        if (empty($_GPC["uid"])) {
            $this->return_msg(-999, array(), "请先登录");
        }
        $user = pdo_get("yzzc_sun_user", array("id" => $_GPC["uid"]), array("now_integral"));
        $uid = $_GPC["uid"];
        $sql = "select id from" . tablename("yzzc_sun_coupon_get") . "where cid=" . $_GPC["cid"] . " and uid=" . "'{$uid}'";
        $isget = pdo_fetch($sql);
        if ($isget) {
            $this->return_msg(-1, array(), "您已领过");
        }
        $info = pdo_get("yzzc_sun_coupon", array("uniacid" => $_W["uniacid"], "id" => $_GPC["cid"]));
        if ($user["now_integral"] < $info["score"]) {
            $this->return_msg(-1, array(), "积分不足，无法兑换");
        }
        if ($info["end_time"] > time()) {
            if ($info["total"] == 0 || $info["total"] > $info["getnum"]) {
                $data["uid"] = $_GPC["uid"];
                $data["cid"] = $_GPC["cid"];
                $data["createtime"] = time();
                $data["uniacid"] = $_W["uniacid"];
                $data["type"] = 1;
                $res = pdo_insert("yzzc_sun_coupon_get", $data);
                pdo_update("yzzc_sun_coupon", array("getnum +=" => 1), array("id" => $_GPC["cid"]));
                if ($res) {
                    $this->scoreAct($uid, 2, -$info["score"]);
                    $this->return_msg(1, array(), "领取成功");
                } else {
                    $this->return_msg(-1, array(), "领取失败");
                }
            } else {
                $this->return_msg(-1, array(), "来晚了，优惠券已领完");
            }
        } else {
            $this->return_msg(-1, array(), "租车券已过期");
        }
    }
    public function doPageIntegralDetails()
    {
        global $_GPC, $_W;
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        if ($_GPC["type"] == 1) {
            $where = array("uniacid" => $_W["uniacid"], "uid" => $_GPC["uid"]);
        } else {
            $where = array("uniacid" => $_W["uniacid"], "uid" => $_GPC["uid"], "type" => 2);
        }
        $res = pdo_getall("yzzc_sun_integral_log", $where, array(), '', array("id desc"), array($page, $length));
        foreach ($res as $key => $value) {
            $res[$key]["createtime"] = date("Y-m-d H:i:s", $value["createtime"]);
        }
        $this->return_msg(1, $res);
    }
    public function doPageFjshop()
    {
        global $_GPC, $_W;
        $lng = $_GPC["lng"];
        $lat = $_GPC["lat"];
        if ($lat && $lng) {
            $sql = "SELECT  id, name,address,ranges,( 6371 * acos (    \n                cos ( radians(" . $lat . ") )    \n                * cos( radians( lat ) )    \n                * cos( radians( lng ) - radians(" . $lng . ") )    \n                + sin ( radians(" . $lat . ") )    \n                * sin( radians( lat ) )    )    \n                ) AS distance FROM ims_yzzc_sun_branch  WHERE uniacid = " . $_W["uniacid"] . " and status =1 and ranges >0 HAVING distance < ranges ORDER BY distance asc";
            $data = pdo_fetchall($sql);
            $this->return_msg(1, $data);
        } else {
            $this->return_msg(-1, array(), "请先获取地理位置");
        }
    }
    public function doPageBranch()
    {
        global $_GPC, $_W;
        if ($_GPC["id"] > 0) {
            $bran = pdo_get("yzzc_sun_branch", array("uniacid" => $_W["uniacid"], "id" => $_GPC["id"], "status" => 1));
            if ($bran) {
                $cityname = $this->getcode($bran["city"]);
                $bran["city_name"] = $cityname["fullname"];
                $areaname = $this->getcode($bran["area"]);
                $bran["area_name"] = $areaname["fullname"];
                if ($bran["pic"]) {
                    $bran["pic"] = explode(",", $bran["pic"]);
                }
                $this->return_msg(1, $bran);
            } else {
                $this->return_msg(-1, array(), "门店不存在");
            }
        } else {
            $this->return_msg(-1, array(), "门店id不存在");
        }
    }
    public function doPageAllshop()
    {
        global $_W;
        $bran = pdo_get("yzzc_sun_branch", array("uniacid" => $_W["uniacid"], "status" => 1));
        $this->return_msg(1, $bran);
    }
    public function doPageSmshop()
    {
        global $_GPC, $_W;
        $lng = $_GPC["lng"];
        $lat = $_GPC["lat"];
        if ($lat && $lng) {
            $sql = "SELECT id,name,address,ranges,city,area,( 6371 * acos (    \n                cos ( radians(" . $lat . ") )    \n                * cos( radians( lat ) )    \n                * cos( radians( lng ) - radians(" . $lng . ") )    \n                + sin ( radians(" . $lat . ") )    \n                * sin( radians( lat ) )    )    \n                ) AS distance FROM ims_yzzc_sun_branch  WHERE uniacid = " . $_W["uniacid"] . " and status =1 and ranges > ( 6371 * acos (    \n                cos ( radians(" . $lat . ") )    \n                * cos( radians( lat ) )    \n                * cos( radians( lng ) - radians(" . $lng . ") )    \n                + sin ( radians(" . $lat . ") )    \n                * sin( radians( lat ) )    )    \n                )  ORDER BY distance";
            $data = pdo_fetchall($sql);
            $this->return_msg(1, $data);
        } else {
            $this->return_msg(-1, array(), "请先获取地理位置");
        }
    }
    public function doPageCartype()
    {
        global $_W;
        $type = pdo_getall("yzzc_sun_cartype", array("uniacid" => $_W["uniacid"]));
        $this->return_msg(1, $type);
    }
    public function doPageCarlist()
    {
        global $_GPC, $_W;
        $filed = array();
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $sid = $_GPC["sid"];
        $stime = $_GPC["stime"];
        $etime = $_GPC["etime"];
        if ($_GPC["cartype"] == 0) {
            if ($_GPC["act"] > 0) {
                $where = array("uniacid" => $_W["uniacid"], "status" => 1, "is_del" => 0, "sid" => $sid, "act_money >" => 0);
            } else {
                $where = array("uniacid" => $_W["uniacid"], "status" => 1, "is_del" => 0, "sid" => $sid);
            }
        } else {
            if ($_GPC["act"] > 0) {
                $where = array("uniacid" => $_W["uniacid"], "is_del" => 0, "status" => 1, "cartype" => $_GPC["cartype"], "sid" => $sid, "act_money >" => 0);
            } else {
                $where = array("uniacid" => $_W["uniacid"], "is_del" => 0, "status" => 1, "cartype" => $_GPC["cartype"], "sid" => $sid);
            }
        }
        $sort = $_GPC["sort"];
        if ($sort == "asc") {
            $orderby = array("money asc");
        } else {
            if ($sort == "desc") {
                $orderby = array("money desc");
            } else {
                $orderby = array("id desc");
            }
        }
        $res = pdo_getall("yzzc_sun_goods", $where, $filed, '', $orderby, array($page, $length));
        $res1 = [];
        foreach ($res as $k => $v) {
            $cid = $v["id"];
            $carnum = $v["carnum"];
            $allorder = pdo_fetchall("select * from " . tablename("yzzc_sun_order") . " where cid = " . $cid . " and uniacid =" . $_W["uniacid"] . " and (status = 2 or status = 3)");
            $allordertime = pdo_fetchall("select * from " . tablename("yzzc_sun_ordertime") . " where uniacid = " . $_W["uniacid"] . " and carnum = '{$carnum}'");
            if ($allordertime) {
                foreach ($allordertime as $key => $value) {
                    $start_time = $value["start_time"];
                    $end_time = $value["end_time"];
                    $starttime = date("Y-m-d H:i:s", $start_time);
                    $endtime = date("Y-m-d H:i:s", $end_time);
                    if ($stime < $start_time && $etime > $end_time && $start_time < $etime && $stime < $end_time) {
                        if ($res[$k] != null) {
                            array_push($res1, $res[$k]);
                            unset($res[$k]);
                        }
                    } else {
                        if ($stime < $start_time && $end_time > $etime && $start_time < $etime && $stime < $end_time) {
                            if ($res[$k] != null) {
                                array_push($res1, $res[$k]);
                                unset($res[$k]);
                            }
                        } else {
                            if ($start_time < $stime && $etime > $end_time && $start_time < $etime && $stime < $end_time) {
                                if ($res[$k] != null) {
                                    array_push($res1, $res[$k]);
                                    unset($res[$k]);
                                }
                            } else {
                                if ($start_time < $stime && $end_time > $etime && $start_time < $etime && $stime < $end_time) {
                                    if ($res[$k] != null) {
                                        array_push($res1, $res[$k]);
                                        unset($res[$k]);
                                    }
                                } else {
                                }
                            }
                        }
                    }
                }
            }
        }
        $info = array("res" => $res, "res1" => $res1);
        $this->return_msg(1, $info, "success");
    }
    public function doPageGetarea()
    {
        global $_GPC, $_W;
        $code = $_GPC["code"];
        $where = " WHERE  uniacid=" . $_W["uniacid"] . " and city =" . $code . " and status= 1 ";
        $sql = "SELECT  distinct  area FROM ims_yzzc_sun_branch " . $where;
        $area = pdo_fetchall($sql);
        foreach ($area as $key => $value) {
            $areainfo = pdo_get("yzzc_sun_city", array("code" => $value["area"]), array("fullname"));
            $area[$key]["fullname"] = $areainfo["fullname"];
        }
        $this->return_msg(1, $area, "success");
    }
    public function doPageAreashop()
    {
        global $_GPC, $_W;
        $where = array("uniacid" => $_W["uniacid"], "area" => $_GPC["code"], "status" => 1);
        $filed = array("id", "name", "address");
        $res = pdo_getall("yzzc_sun_branch", $where, $filed, "id desc");
        $this->return_msg(1, $res, "success");
    }
    public function doPageCityshop()
    {
        global $_GPC, $_W;
        $where = array("uniacid" => $_W["uniacid"], "city" => $_GPC["code"], "status" => 1);
        $filed = array("id", "name", "city", "area");
        $res = pdo_getall("yzzc_sun_branch", $where, $filed, "id desc");
        foreach ($res as $key => $val) {
            $cityname = $this->getcode($val["city"]);
            $res[$key]["city_name"] = $cityname["fullname"];
            $areaname = $this->getcode($val["area"]);
            $res[$key]["area_name"] = $areaname["fullname"];
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPageAllcity()
    {
        global $_W;
        $where = " WHERE  uniacid=" . $_W["uniacid"] . " and status= 1 ";
        $sql = "SELECT  distinct  city FROM ims_yzzc_sun_branch " . $where;
        $area = pdo_fetchall($sql);
        foreach ($area as $key => $value) {
            $areainfo = pdo_get("yzzc_sun_city", array("code" => $value["city"]), array("fullname"));
            $area[$key]["fullname"] = $areainfo["fullname"];
        }
        $this->return_msg(1, $area, "success");
    }
    function mylevel($score)
    {
        global $_W;
        $res = pdo_getall("yzzc_sun_level", array("uniacid" => $_W["uniacid"]), array(), '', array("level_score asc"));
        $arr = array();
        foreach ($res as $val) {
            array_push($arr, $val["level_score"]);
        }
        $level = 0;
        foreach ($arr as $key => $value) {
            if ($score > $value) {
                $level++;
            }
        }
        $myres = pdo_getall("yzzc_sun_level", array("uniacid" => $_W["uniacid"]), array(), '', array("level_score asc"));
        if ($level > 0) {
            $mylevel = $myres[$level - 1];
        } else {
            $mylevel = $myres[$level];
        }
        return $mylevel;
    }
    function mytq($score)
    {
        global $_W;
        $res = pdo_getall("yzzc_sun_level", array("uniacid" => $_W["uniacid"]), array(), '', array("level_score asc"));
        $arr = array();
        foreach ($res as $val) {
            if ($score > $val["level_score"]) {
                array_push($arr, $val);
            }
        }
        if (empty($arr)) {
            $arr[0] = $res[0];
        }
        return $arr;
    }
    public function doPageMember()
    {
        global $_GPC, $_W;
        $user = pdo_get("yzzc_sun_user", array("id" => $_GPC["uid"]), array("all_integral", "user_name", "headimg"));
        $res = pdo_getall("yzzc_sun_level", array("uniacid" => $_W["uniacid"]), array(), "level_score asc");
        $score = array();
        foreach ($res as $val) {
            array_push($score, $val["level_score"]);
        }
        $now = $user["all_integral"];
        $level = 0;
        foreach ($score as $key => $value) {
            if ($now > $value) {
                $level++;
            }
        }
        if ($level == count($res)) {
            $data["cha"] = -1;
        } else {
            $myres = pdo_getall("yzzc_sun_level", array("uniacid" => $_W["uniacid"]), array(), "level_score asc", $level, 2);
            $cha = $myres[1]["level_score"] - $user["all_integral"];
            $data["cha"] = $cha;
        }
        $data["list"] = $res;
        $data["mylevel"] = $this->mylevel($user["all_integral"]);
        $rule = pdo_get("yzzc_sun_allrule", array("uniacid" => $_W["uniacid"], "type" => 2), array("content"));
        $data["rule"] = $rule["content"];
        $data["userinfo"] = $user;
        $this->return_msg(1, $data, "success");
    }
    function getTimeWeek($time, $i = 0)
    {
        $weekarray = array("日", "一", "二", "三", "四", "五", "六");
        $oneD = 24 * 60 * 60;
        return "周" . $weekarray[date("w", $time + $oneD * $i)];
    }
    function carInfo($cid)
    {
        $info = pdo_get("yzzc_sun_goods", array("id" => $cid, "status" => 1));
        return $info;
    }
    function getcode($code)
    {
        $cityinfo = pdo_get("yzzc_sun_city", array("code" => $code));
        return $cityinfo;
    }
    public function doPageShopname()
    {
        global $_GPC, $_W;
        $sid = $_GPC["sid"];
        $info = pdo_get("yzzc_sun_branch", array("id" => $sid), array("id", "name", "province", "city", "area"));
        if ($info) {
            $info["province_name"] = $this->getcode($info["province"])["fullname"];
            $info["city_name"] = $this->getcode($info["city"])["fullname"];
            $info["area_name"] = $this->getcode($info["area"])["fullname"];
        }
        $this->return_msg(1, $info, "success");
    }
    public function doPageYdcar()
    {
        global $_GPC, $_W;
        $info = $this->carInfo($_GPC["cid"]);
        $ordertime = pdo_fetchall("select * from " . tablename("yzzc_sun_ordertime") . " where carnum = '" . $info["carnum"] . "' and uniacid = " . $_W["uniacid"] . " and end_time >" . time() . " order by start_time desc");
        foreach ($ordertime as $key => $value) {
            $ordertime[$key]["start_time"] = date("Y-m-d H:i:s", $value["start_time"]);
            $ordertime[$key]["end_time"] = date("Y-m-d H:i:s", $value["end_time"]);
        }
        $info["ordertime"] = $ordertime;
        $info["shopinfo"] = pdo_get("yzzc_sun_branch", array("id" => $info["sid"]), array("id", "name", "province", "city", "area"));
        $info["shopinfo"]["province_name"] = $this->getcode($info["shopinfo"]["province"])["fullname"];
        $info["shopinfo"]["city_name"] = $this->getcode($info["shopinfo"]["city"])["fullname"];
        $info["shopinfo"]["area_name"] = $this->getcode($info["shopinfo"]["area"])["fullname"];
        $this->return_msg(1, $info, "success");
    }
    public function doPagexzdetail()
    {
        global $_W, $_GPC;
        $oid = $_GPC["oid"];
        $day = $_GPC["day"] ? $_GPC["day"] : 1;
        $data = pdo_get("yzzc_sun_order", array("uniacid" => $_W["uniacid"], "id" => $oid, "status" => 3));
        $data["carinfo"] = pdo_get("yzzc_sun_goods", array("uniacid" => $_W["uniacid"], "id" => $data["cid"]));
        $allday = [];
        $i = 0;
        while ($i < $day) {
            array_push($allday, date("Y-m-d", $data["end_time"] + $i * 24 * 60 * 60));
            $i++;
        }
        $money = 0;
        $spec = [];
        if ($data["carinfo"]["subscribe_duration"]) {
            $data["carinfo"]["spec"] = pdo_fetchall("select * from " . tablename("yzzc_sun_specprice") . " where uniacid =" . $_W["uniacid"] . " and gid = " . $data["cid"] . " order by spec asc");
            foreach ($data["carinfo"]["spec"] as $key => $value) {
                foreach ($allday as $k => $v) {
                    if ($value["spec"] == $v) {
                        $money += $value["price"];
                        array_push($spec, $value);
                        unset($allday[$k]);
                    }
                }
            }
        }
        $user = pdo_get("yzzc_sun_user", array("id" => $data["uid"]), array("all_integral", "now_integral"));
        $levelinfo = $this->mylevel($user["all_integral"]);
        if ($levelinfo["level_privileges"] == 2) {
            $data["is_service_fee"] = 0;
            $data["carinfo"]["service_fee"] = 0;
        } else {
            $data["is_service_fee"] = 1;
        }
        $data["time"]["day"] = count($allday);
        $data["carinfo"]["specprice"] = $money;
        $data["carinfo"]["spec"] = $spec;
        $data["carinfo"]["specday"] = count($spec);
        $orderset = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("know", "long_prepay", "short_prepay", "service_desc", "zx_service_desc", "rule", "zchetong"));
        $data["orderset"] = $orderset;
        $data["shopinfo"] = pdo_get("yzzc_sun_branch", array("id" => $data["carinfo"]["sid"]), array("id", "name", "province", "city", "area"));
        $data["shopinfo"]["province_name"] = $this->getcode($data["shopinfo"]["province"])["fullname"];
        $data["shopinfo"]["city_name"] = $this->getcode($data["shopinfo"]["city"])["fullname"];
        $data["shopinfo"]["area_name"] = $this->getcode($data["shopinfo"]["area"])["fullname"];
        $integralset = pdo_get("yzzc_sun_integralset", array("uniacid" => $_W["uniacid"]), array("use_score", "use_money"));
        $data["integral_set"] = $integralset;
        if ($integralset["use_score"] > 0) {
            $ystotal = $data["carinfo"]["money"] * $data["time"]["day"] + $data["carinfo"]["service_fee"] * $data["time"]["day"] + $money;
            $ystotal = intval($ystotal);
            $allscore = $ystotal * intval($data["integral_set"]["use_score"]) / intval($integralset["use_money"]);
            $data["user"] = pdo_get("yzzc_sun_user", array("id" => $data["uid"]), array("now_integral"));
            if ($allscore > $data["user"]["now_integral"]) {
                $data["kdmoney"] = $data["user"]["now_integral"] / $integralset["use_score"] * $integralset["use_money"];
                $data["kdscore"] = $data["user"]["now_integral"];
            } else {
                $data["kdscore"] = $allscore;
                $data["kdmoney"] = $allscore / $integralset["use_score"] * $integralset["use_money"];
            }
            $data["kdmoney"] = sprintf("%.2f", $data["kdmoney"]);
            $data["kycoupontotal"] = $ystotal - $data["kdmoney"] - 0.01;
        }
        $this->return_msg(1, $data, "success");
    }
    public function doPagexzOrder()
    {
        global $_GPC, $_W;
        $oid = $_GPC["oid"];
        $order = pdo_get("yzzc_sun_order", array("uniacid" => $_W["uniacid"], "id" => $oid, "status" => 3));
        if (!$order) {
            $this->return_msg(-1, array(), "续租失败！");
        }
        if ($order["iszx"] == 1) {
            $this->return_msg(-1, array(), "该订单已续租，无法重复续租！");
        }
        $xzorder = pdo_get("yzzc_sun_xzorder", array("uniacid" => $_W["uniacid"], "ordernum" => $order["ordernum"]));
        if ($xzorder["ispay"] == 1) {
            $this->return_msg(-1, array(), "该订单已续租，无法重复续租！");
        }
        $data["uniacid"] = $_W["uniacid"];
        $data["createtime"] = time();
        $start_time = $order["end_time"];
        $end_time = $_GPC["end_time"];
        $couponid = $_GPC["couponid"];
        $carinfo = pdo_get("yzzc_sun_goods", array("id" => $order["cid"], "status !=" => 3, "is_del" => 0));
        if ($carinfo) {
            $data["start_time"] = $start_time;
            $data["end_time"] = $end_time;
            $day = $_GPC["day"];
            $data["day"] = $day;
            $data["money"] = $order["money"];
            $user = pdo_get("yzzc_sun_user", array("id" => $order["uid"]), array("all_integral", "now_integral"));
            $levelinfo = $this->mylevel($user["all_integral"]);
            if ($levelinfo["level_privileges"] == 2) {
                $data["service_fee"] = 0;
            } else {
                $data["service_fee"] = $carinfo["service_fee"];
            }
            if ($levelinfo["level_privileges"] == 3) {
                $data["end_time"] = $end_time + $levelinfo["delay"] * 60 * 60;
            }
            if ($carinfo["zx_service_fee"] > 0) {
                $data["open_zx_service"] = $_GPC["open_zx_service"];
                if ($_GPC["open_zx_service"] == 1) {
                    $data["zx_service_fee"] = $carinfo["zx_service_fee"];
                }
            }
            $data["integral_money"] = 0;
            if ($_GPC["open_integral"] == 1) {
                if ($user["now_integral"] >= $_GPC["integral"]) {
                    $data["integral_money"] = $_GPC["integral_money"];
                    $data["integral"] = $_GPC["integral"];
                    if ($data["integral"] > 0) {
                        $this->scoreAct($order["uid"], 4, -$data["integral"]);
                    }
                }
            }
            $data["coupon"] = 0;
            if ($couponid > 0) {
                $coupon = pdo_get("yzzc_sun_coupon", array("id" => $couponid));
                $data["coupon_money"] = $coupon["money"];
                $data["coupon"] = $couponid;
                pdo_update("yzzc_sun_coupon_get", array("isuse" => 1, "usetime" => time()), array("cid" => $couponid, "uid" => $order["uid"]));
            }
            $data["total_money"] = $_GPC["total_money"];
            $data["ordernum"] = $order["ordernum"];
            pdo_insert("yzzc_sun_xzorder", $data);
            $oid = pdo_insertid();
            include_once IA_ROOT . "/addons/" . $_W["current_module"]["name"] . "/inc/func/distribution.php";
            $user = pdo_get("yzzc_sun_user", array("id" => $order["uid"]));
            $distribution = new Distribution();
            $distribution->order_id = $order["id"];
            $distribution->money = $data["total_money"];
            $distribution->userid = $user["openid"];
            $distribution->ordertype = 3;
            $distribution->computecommission();
            if ($oid) {
                $this->return_msg(1, $oid, "success");
            }
        } else {
            $this->return_msg(-1, array(), "当前车辆已下架，无法续租！");
        }
    }
    public function doPageCheckOrd()
    {
        global $_GPC, $_W;
        $cid = $_GPC["cid"];
        $uid = $_GPC["uid"];
        $start_time = date("Y-m-d", $_GPC["start_time"]);
        $end_time = date("Y-m-d", $_GPC["end_time"]);
        $user_drive = pdo_get("yzzc_sun_user_drive", array("uniacid" => $_W["uniacid"], "is_mr" => 1, "uid" => $uid));
        $data["user_drive"] = $user_drive;
        $day = $_GPC["day"] - 0;
        $allday = [];
        $i = 0;
        while ($i < $day) {
            array_push($allday, date("Y-m-d", $_GPC["start_time"] + $i * 24 * 60 * 60));
            $i++;
        }
        $money = 0;
        $spec = [];
        $data["carinfo"] = pdo_get("yzzc_sun_goods", array("id" => $cid, "status" => 1));
        if ($data["carinfo"]["subscribe_duration"]) {
            $data["carinfo"]["spec"] = pdo_fetchall("select * from " . tablename("yzzc_sun_specprice") . " where uniacid =" . $_W["uniacid"] . " and gid = " . $cid . " order by spec asc");
            foreach ($data["carinfo"]["spec"] as $key => $value) {
                foreach ($allday as $k => $v) {
                    if ($value["spec"] == $v) {
                        $money += $value["price"];
                        array_push($spec, $value);
                        unset($allday[$k]);
                    }
                }
            }
        }
        $data["time"]["day"] = count($allday);
        $data["carinfo"]["specprice"] = $money;
        $data["carinfo"]["spec"] = $spec;
        $data["carinfo"]["specday"] = count($spec);
        $data["shopinfo"] = pdo_get("yzzc_sun_branch", array("id" => $data["carinfo"]["sid"]), array("id", "name", "province", "city", "area"));
        $data["shopinfo"]["province_name"] = $this->getcode($data["shopinfo"]["province"])["fullname"];
        $data["shopinfo"]["city_name"] = $this->getcode($data["shopinfo"]["city"])["fullname"];
        $data["shopinfo"]["area_name"] = $this->getcode($data["shopinfo"]["area"])["fullname"];
        $user = pdo_get("yzzc_sun_user", array("id" => $uid), array("all_integral", "now_integral"));
        $levelinfo = $this->mylevel($user["all_integral"]);
        if ($levelinfo["level_privileges"] == 2) {
            $data["is_service_fee"] = 0;
            $data["carinfo"]["service_fee"] = 0;
        } else {
            $data["is_service_fee"] = 1;
        }
        $integralset = pdo_get("yzzc_sun_integralset", array("uniacid" => $_W["uniacid"]), array("use_score", "use_money"));
        $data["integral_set"] = $integralset;
        if ($integralset["use_score"] > 0) {
            $ystotal = $data["carinfo"]["money"] * $data["time"]["day"] + $data["carinfo"]["service_fee"] * $data["time"]["day"] + $data["carinfo"]["fee"] + $money;
            $ystotal = intval($ystotal);
            $allscore = $ystotal * intval($data["integral_set"]["use_score"]) / intval($integralset["use_money"]);
            $data["user"] = pdo_get("yzzc_sun_user", array("id" => $uid), array("now_integral"));
            if ($allscore > $data["user"]["now_integral"]) {
                $data["kdmoney"] = $data["user"]["now_integral"] / $integralset["use_score"] * $integralset["use_money"];
                $data["kdscore"] = $data["user"]["now_integral"];
            } else {
                $data["kdscore"] = $allscore;
                $data["kdmoney"] = $allscore / $integralset["use_score"] * $integralset["use_money"];
            }
            $data["kdmoney"] = sprintf("%.2f", $data["kdmoney"]);
            $data["kycoupontotal"] = $ystotal - $data["kdmoney"] - 0.01;
        }
        $orderset = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("know", "long_prepay", "short_prepay", "service_desc", "zx_service_desc", "rule", "zchetong", "depositway", "deposit"));
        $data["orderset"] = $orderset;
        $this->return_msg(1, $data, "success");
    }
    public function doPageKycoupon()
    {
        global $_GPC, $_W;
        $uid = $_GPC["uid"];
        $where = " WHERE  a.uniacid=" . $_W["uniacid"] . " and a.end_time >" . time() . " and a.start_time < " . time() . " and b.isuse = 0 and a.full < " . $_GPC["full"];
        $sql = "select a.id,a.start_time,a.end_time,a.money,a.full,a.limit,b.usetime,b.createtime,b.isuse,a.type  from " . tablename("yzzc_sun_coupon") . "a " . "left join" . tablename("yzzc_sun_coupon_get") . "b on b.cid=a.id and b.uid= " . "{$uid}.{$where}";
        $kycoupon = pdo_fetchall($sql);
        $this->return_msg(1, $kycoupon, "success");
    }
    public function doPageIsorder()
    {
        global $_GPC, $_W;
        $cid = $_GPC["cid"];
        $carnum = $_GPC["carnum"];
        $uid = $_GPC["uid"];
        $stime = $_GPC["stime"];
        $etime = $_GPC["etime"];
        $order = pdo_fetch("select id from " . tablename("yzzc_sun_order") . " where uniacid = " . $_W["uniacid"] . " and carnum = '{$carnum}' and (status = 2 or status = 3)");
        if (!$order) {
            $allorder = pdo_fetchall("select * from " . tablename("yzzc_sun_ordertime") . " where uniacid = " . $_W["uniacid"] . " and carnum = '{$carnum}'");
            foreach ($allorder as $key => $value) {
                $start_time = $value["start_time"];
                $end_time = $value["end_time"];
                $starttime = date("Y-m-d H:i:s", $start_time);
                $endtime = date("Y-m-d H:i:s", $end_time);
                if ($stime < $start_time && $etime > $end_time && $start_time < $etime && $stime < $end_time) {
                    $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                } else {
                    if ($stime < $start_time && $end_time > $etime && $start_time < $etime && $stime < $end_time) {
                        $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                    } else {
                        if ($start_time < $stime && $etime > $end_time && $start_time < $etime && $stime < $end_time) {
                            $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                        } else {
                            if ($start_time < $stime && $end_time > $etime && $start_time < $etime && $stime < $end_time) {
                                $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                            } else {
                            }
                        }
                    }
                }
            }
            $this->return_msg(1, array(), "首次下单");
        } else {
            $allorder = pdo_fetchall("select * from " . tablename("yzzc_sun_ordertime") . " where uniacid = " . $_W["uniacid"] . " and carnum = '{$carnum}'");
            foreach ($allorder as $key => $value) {
                $start_time = $value["start_time"];
                $end_time = $value["end_time"];
                $starttime = date("Y-m-d H:i:s", $start_time);
                $endtime = date("Y-m-d H:i:s", $end_time);
                if ($stime < $start_time && $etime > $end_time && $start_time < $etime && $stime < $end_time) {
                    $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                } else {
                    if ($stime < $start_time && $end_time > $etime && $start_time < $etime && $stime < $end_time) {
                        $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                    } else {
                        if ($start_time < $stime && $etime > $end_time && $start_time < $etime && $stime < $end_time) {
                            $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                        } else {
                            if ($start_time < $stime && $end_time > $etime && $start_time < $etime && $stime < $end_time) {
                                $this->return_msg(-2, array(), "您选择的时间车辆已被出租,时间为：" . $starttime . "--" . $endtime);
                            } else {
                            }
                        }
                    }
                }
            }
            $this->return_msg(1, array(), "下单");
        }
    }
    public function doPageOrderInfo()
    {
        global $_GPC, $_W;
        $order = pdo_get("yzzc_sun_order", array("id" => $_GPC["oid"]));
        $order["carinfo"] = $this->carInfo($order["cid"]);
        $info = pdo_get("yzzc_sun_branch", array("id" => $order["start_shop"]), array("id", "name", "province", "city", "area"));
        if ($info) {
            $info["province_name"] = $this->getcode($info["province"])["fullname"];
            $info["city_name"] = $this->getcode($info["city"])["fullname"];
            $info["area_name"] = $this->getcode($info["area"])["fullname"];
        }
        $order["shop"] = $info;
        $order["qcrule"] = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("getcar_desc"))["getcar_desc"];
        if ($order) {
            $this->return_msg(1, $order, "success");
        } else {
            $this->return_msg(-1, array(), "订单不存在");
        }
    }
    public function doPageorderpj()
    {
        global $_GPC, $_W;
        $oid = $_GPC["oid"];
        $order = pdo_get("yzzc_sun_order", array("uniacid" => $_W["uniacid"], "id" => $oid));
        if ($order["status"] == 0 || $order["status"] == 3 || $order["status"] == 2) {
            if ($order["ispl"] == 0) {
                $data["content"] = $_GPC["content"];
                $data["img"] = $_GPC["img"];
                $data["oid"] = $_GPC["oid"];
                $data["time"] = time();
                $data["uniacid"] = $_W["uniacid"];
                $data["carnum"] = $order["carnum"];
                $res = pdo_insert("yzzc_sun_orderpinglun", $data);
                if ($res) {
                    $result = pdo_update("yzzc_sun_order", array("ispl" => 1), array("uniacid" => $_W["uniacid"], "id" => $oid));
                    $this->return_msg(1, array(), "评价成功");
                } else {
                    $this->return_msg(-1, array(), "评价失败");
                }
            } else {
                $this->return_msg(-1, array(), "当前订单已评价，无法重复评价！");
            }
        } else {
            $this->return_msg(-1, array(), "当前订单无法评价！");
        }
    }
    public function doPageOrderList()
    {
        global $_GPC, $_W;
        $type = $_GPC["type"] ? $_GPC["type"] : 1;
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $res = pdo_getall("yzzc_sun_order", array("uniacid" => $_W["uniacid"], "type" => $type, "uid" => $_GPC["uid"], "display" => 1), array(), '', array("status asc", "createtime desc"), array($page, $length));
        $set = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("istui", "tuimoney", "open_xz", "xztime"));
        $day = $set["istui"] * 24 * 60 * 60;
        $hour = $set["xztime"] * 60 * 60;
        $time = time();
        foreach ($res as $key => $val) {
            $res[$key]["carinfo"] = pdo_get("yzzc_sun_goods", array("id" => $val["cid"]));
            if ($res) {
                if ($val["usetime"]) {
                    $res[$key]["usetime"] = date("Y-m-d H:i:s", $val["usetime"]);
                }
                $info = pdo_get("yzzc_sun_branch", array("id" => $val["start_shop"]), array("id", "name", "province", "city", "area"));
                $info["province_name"] = $this->getcode($info["province"])["fullname"];
                $info["city_name"] = $this->getcode($info["city"])["fullname"];
                $info["area_name"] = $this->getcode($info["area"])["fullname"];
                $res[$key]["shop"] = $info;
                $res[$key]["set"] = $set;
                if ($val["start_time"] - $day > $time) {
                    $res[$key]["state"] = 1;
                } else {
                    if ($val["start_time"] - $day < $time) {
                        $res[$key]["state"] = 2;
                    }
                }
                if ($val["iszx"] == 1) {
                    $xzorder = pdo_get("yzzc_sun_xzorder", array("uniacid" => $_W["uniacid"], "ordernum" => $val["ordernum"], "ispay" => 1));
                    $res[$key]["end_time"] = $xzorder["end_time"];
                    $res[$key]["day"] = $val["day"] + $xzorder["day"];
                }
                if ($val["return_time"]) {
                    $res[$key]["return_time"] = date("Y-m-d H:i:s", $res[$key]["return_time"]);
                }
                if ($set["open_xz"] == 1) {
                    if ($res[$key]["carinfo"]["open_xz"] == 1) {
                        if ($val["end_time"] - $hour > $time) {
                            $res[$key]["open_xz"] = 1;
                        } else {
                            $res[$key]["open_xz"] = 0;
                        }
                    } else {
                        $res[$key]["open_xz"] = 0;
                    }
                } else {
                    $res[$key]["open_xz"] = 0;
                }
            }
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPagerefund()
    {
        global $_W, $_GPC;
        $id = $_GPC["oid"];
        $uniacid = $_W["uniacid"];
        $res = pdo_update("yzzc_sun_order", array("istui" => 1), array("uniacid" => $_W["uniacid"], "id" => $id));
        if ($res) {
            $this->return_msg(1, array(), "申请成功");
        } else {
            $this->return_msg(-1, array(), "申请失败");
        }
    }
    public function doPagerefundcancel()
    {
        global $_W, $_GPC;
        $id = $_GPC["oid"];
        $uniacid = $_W["uniacid"];
        $res = pdo_update("yzzc_sun_order", array("istui" => 0), array("uniacid" => $_W["uniacid"], "id" => $id, "status" => 2));
        if ($res) {
            $this->return_msg(1, array(), "取消成功");
        } else {
            $this->return_msg(-1, array(), "取消失败");
        }
    }
    public function doPagerefundDeposit()
    {
        global $_W, $_GPC;
        $id = $_GPC["oid"];
        $uniacid = $_W["uniacid"];
        $res = pdo_update("yzzc_sun_order", array("isdeposit" => 1), array("uniacid" => $_W["uniacid"], "id" => $id));
        if ($res) {
            $this->return_msg(1, array(), "申请成功");
        } else {
            $this->return_msg(-1, array(), "申请失败");
        }
    }
    public function doPagerefundcancelDeposit()
    {
        global $_W, $_GPC;
        $id = $_GPC["oid"];
        $uniacid = $_W["uniacid"];
        $res = pdo_update("yzzc_sun_order", array("isdeposit" => 0), array("uniacid" => $_W["uniacid"], "id" => $id));
        if ($res) {
            $this->return_msg(1, array(), "取消成功");
        } else {
            $this->return_msg(-1, array(), "取消失败");
        }
    }
    public function doPageOrder()
    {
        global $_GPC, $_W;
        $cid = $_GPC["cid"];
        $carnum = $_GPC["carnum"];
        $uid = $_GPC["uid"];
        $isorder = pdo_get("yzzc_sun_order", array("cid" => $cid, "uid" => $uid, "ispay" => 0, "isuse" => 0, "status !=" => 4), array("id"));
        $data["uniacid"] = $_W["uniacid"];
        $data["createtime"] = time();
        $start_time = $_GPC["start_time"];
        $end_time = $_GPC["end_time"];
        $start_shop = $_GPC["start_shop"];
        $end_shop = $_GPC["end_shop"];
        $type = $_GPC["type"];
        $typeid = $_GPC["typeid"];
        $gettype = $_GPC["gettype"];
        $couponid = $_GPC["couponid"];
        $active = $_GPC["active"];
        $carinfo = pdo_get("yzzc_sun_goods", array("id" => $cid, "status" => 1, "is_del" => 0));
        if ($carinfo) {
            $data["cid"] = $cid;
            $data["carnum"] = $carnum;
            $data["gettype"] = $gettype;
            $data["type"] = $type;
            $data["start_time"] = $start_time;
            $data["end_time"] = $end_time;
            $data["start_shop"] = $start_shop;
            $data["end_shop"] = $end_shop;
            $data["uid"] = $uid;
            $day = $_GPC["day"];
            $data["day"] = $day;
            if ($type == 2) {
                $taocan = pdo_get("yzzc_sun_taocan", array("id" => $typeid));
                if ($taocan["day"] > $day) {
                    $this->return_msg(-1, array(), "该车辆至少" . $taocan["day"] . "天起订");
                }
                $data["money"] = $carinfo["money"] - $carinfo["money"] * ($taocan["money"] / 100);
                $data["money"] = sprintf("%.2f", $data["money"]);
            } else {
                if ($active == 1) {
                    $data["active"] = $active;
                    $data["money"] = $carinfo["act_money"];
                } else {
                    $data["money"] = $carinfo["money"];
                }
            }
            $data["fee"] = $carinfo["fee"];
            $user = pdo_get("yzzc_sun_user", array("id" => $uid), array("all_integral", "now_integral"));
            $levelinfo = $this->mylevel($user["all_integral"]);
            if ($levelinfo["level_privileges"] == 2) {
                $data["service_fee"] = 0;
            } else {
                $data["service_fee"] = $carinfo["service_fee"];
            }
            if ($levelinfo["level_privileges"] == 3) {
                $data["end_time"] = $end_time + $levelinfo["delay"] * 60 * 60;
            }
            if ($carinfo["zx_service_fee"] > 0) {
                $data["open_zx_service"] = $_GPC["open_zx_service"];
                if ($_GPC["open_zx_service"] == 1) {
                    $data["zx_service_fee"] = $carinfo["zx_service_fee"];
                }
            }
            $ystotal = $data["money"] * $day + $data["service_fee"] * $day + $data["fee"] + $data["zx_service_fee"] * $day;
            $data["integral_money"] = 0;
            if ($_GPC["open_integral"] == 1) {
                if ($user["now_integral"] >= $_GPC["integral"]) {
                    $data["integral_money"] = $_GPC["integral_money"];
                    $data["integral"] = $_GPC["integral"];
                    if ($data["integral"] > 0) {
                        $this->scoreAct($uid, 4, -$data["integral"]);
                    }
                }
            }
            $data["coupon"] = 0;
            if ($couponid > 0) {
                $coupon = pdo_get("yzzc_sun_coupon", array("id" => $couponid));
                $data["coupon_money"] = $coupon["money"];
                $data["coupon"] = $couponid;
                pdo_update("yzzc_sun_coupon_get", array("isuse" => 1, "usetime" => time()), array("cid" => $couponid, "uid" => $uid));
            }
            $data["total_money"] = $_GPC["total_money"];
            $data["deposit_money"] = $_GPC["deposit_money"];
            $orderset = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("know", "long_prepay", "short_prepay", "getcar_desc", "rule"));
            if ($orderset["short_prepay"] > 0 && $type == 1) {
                $data["prepay_money"] = $orderset["short_prepay"];
            } else {
                if ($orderset["long_prepay"] > 0 && $type == 2) {
                    $data["prepay_money"] = $orderset["long_prepay"];
                } else {
                    $data["prepay_money"] = $_GPC["total_money"] - $_GPC["deposit_money"];
                }
            }
            $data["ordernum"] = date("YmdHis") . str_pad(mt_rand(1, 9999), 4, "0", STR_PAD_LEFT);
            $data["username"] = $_GPC["username"];
            $data["tel"] = $_GPC["tel"];
            $data["driveid"] = $_GPC["driveid"];
            if (empty($_GPC["driveid"])) {
                $this->return_msg(-1, array(), "请选择驾驶员！");
            }
            pdo_insert("yzzc_sun_order", $data);
            $oid = pdo_insertid();
            include_once IA_ROOT . "/addons/" . $_W["current_module"]["name"] . "/inc/func/distribution.php";
            $user = pdo_get("yzzc_sun_user", array("id" => $uid));
            $distribution = new Distribution();
            $distribution->order_id = $oid;
            $distribution->money = $data["prepay_money"];
            $distribution->userid = $user["openid"];
            $distribution->ordertype = $type;
            $distribution->computecommission();
            if ($oid) {
                $this->return_msg(1, $oid, "success");
            }
        } else {
            $this->return_msg(-1, array(), "车辆不存在");
        }
    }
    public function doPageGetcar()
    {
        global $_GPC, $_W;
        $oid = $_GPC["oid"];
        $res = pdo_get("yzzc_sun_order", array("uniacid" => $_W["uniacid"], "id" => $oid));
        if ($res["ispay"] == 1 && $res["isuse"] == 0) {
            $data["isuse"] = 1;
            $data["usetime"] = time();
            $data["username"] = $_GPC["username"];
            $data["tel"] = $_GPC["tel"];
            $data["status"] = 3;
            $up = pdo_update("yzzc_sun_order", $data, array("id" => $oid));
            if ($up) {
                $this->return_msg(1, array(), "取车成功");
            } else {
                $this->return_msg(-1, array(), "取车失败");
            }
        } else {
            $this->return_msg(-1, array(), "该订单无法取车，请先核对订单");
        }
    }
    public function doPageCancel()
    {
        global $_GPC, $_W;
        $oid = $_GPC["oid"];
        $res = pdo_get("yzzc_sun_order", array("uniacid" => $_W["uniacid"], "id" => $oid));
        if ($res["ispay"] == 0 && $res["isuse"] == 0) {
            $data["status"] = 4;
            $up = pdo_update("yzzc_sun_order", $data, array("id" => $oid));
            pdo_update("yzzc_sun_coupon_get", ["isuse" => 0, "usetime" => 0], array("uid" => $res["uid"], "cid" => $res["coupon"]));
            if ($up) {
                $this->return_msg(1, array(), "取消成功");
            } else {
                $this->return_msg(-1, array(), "取消失败");
            }
        } else {
            $this->return_msg(-1, array(), "该订单已支付无法取消");
        }
    }
    public function doPageAdminInfo()
    {
        global $_GPC, $_W;
        if ($_GPC["uid"]) {
            $user = pdo_get("yzzc_sun_user", array("id" => $_GPC["uid"]), array("isadmin"));
            $day = strtotime(date("Y-m-d", time()));
            if ($user["isadmin"] == 1) {
                $data["todayorder"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_order") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"]);
                $todayordermoney = pdo_fetch("SELECT SUM(prepay_money) as money FROM " . tablename("yzzc_sun_order") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"] . " and (status = 2 or status =3 or status = 0)");
                $todayordermoney1 = pdo_fetch("SELECT SUM(total_money) as money FROM " . tablename("yzzc_sun_xzorder") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"] . " and ispay = 1");
                $data["todayordermoney"] = $todayordermoney["money"] + $todayordermoney1["money"];
                $data["todayuser"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_user") . "where time >" . $day . " and uniacid = " . $_W["uniacid"]);
                $data["allshop"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_branch") . "where uniacid = " . $_W["uniacid"]);
                $data["allcar"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_goods") . "where is_del = 0 and uniacid = " . $_W["uniacid"]);
                $data["allorder"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_order") . "where uniacid = " . $_W["uniacid"]);
                $data["todaysign"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_signlog") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"]);
                $data["admininfo"] = 0;
                $this->return_msg(1, $data);
            } else {
                $branchadmin = pdo_get("yzzc_sun_branch_admin", array("uid" => $_GPC["uid"]));
                if ($branchadmin) {
                    $data["admininfo"] = $branchadmin;
                    $data["branchinfo"] = pdo_get("yzzc_sun_branch", array("id" => $branchadmin["bid"]));
                    $data["todayorder"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_order") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"] . " and start_shop =" . $branchadmin["bid"]);
                    $todayordermoney = pdo_fetch("SELECT SUM(prepay_money) as money FROM " . tablename("yzzc_sun_order") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"] . " and (status = 2 or status =3 or status = 0) and start_shop =" . $branchadmin["bid"]);
                    $todayordermoney1 = pdo_fetch("SELECT SUM(xzmoney) as money FROM " . tablename("yzzc_sun_order") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"] . " and (status = 2 or status =3 or status = 0) and start_shop =" . $branchadmin["bid"]);
                    $data["todayordermoney"] = $todayordermoney["money"] + $todayordermoney1["money"];
                    $data["todayuser"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_user") . "where time >" . $day . " and uniacid = " . $_W["uniacid"]);
                    $data["allshop"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_branch") . "where uniacid = " . $_W["uniacid"]);
                    $data["allcar"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_goods") . "where is_del = 0 and uniacid = " . $_W["uniacid"] . " and sid =" . $branchadmin["bid"]);
                    $data["allorder"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_order") . "where uniacid = " . $_W["uniacid"] . " and start_shop =" . $branchadmin["bid"]);
                    $data["todaysign"] = pdo_fetchcolumn("SELECT COUNT(id) FROM " . tablename("yzzc_sun_signlog") . "where createtime >" . $day . " and uniacid = " . $_W["uniacid"]);
                    $this->return_msg(1, $data);
                } else {
                    $this->return_msg(-1, array(), "您还不是管理员哦");
                }
            }
        } else {
            $this->return_msg(-1, array(), "uid不能为空");
        }
    }
    public function doPageOrderarr()
    {
        include_once "wxpay.php";
        global $_GPC, $_W;
        $oid = intval($_GPC["oid"]);
        $out_trade_no = rand(10000, 99999) . time() . rand(10000, 99999) . $oid;
        $orderinfo = pdo_get("yzzc_sun_order", array("id" => $oid, "uniacid" => $_W["uniacid"]), array("prepay_money", "deposit_money"));
        pdo_update("yzzc_sun_order", array("out_trade_no" => $out_trade_no), array("id" => $oid));
        $total_fee = $orderinfo["prepay_money"] + $orderinfo["deposit_money"];
        $appData = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]));
        $appid = $appData["appid"];
        $mch_id = $appData["mchid"];
        $key = $appData["wxkey"];
        $openid = $_GPC["openid"];
        $total_fee = $total_fee * 100;
        $body = "订单支付";
        $notify_url = $_W["siteroot"] . "addons/yzzc_sun/notify.php";
        $attach = $_W["uniacid"] . "@@@0@@@" . $oid;
        $wxpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $attach, $notify_url);
        $ret = $wxpay->pay();
        $this->return_msg(1, $ret);
    }
    public function doPageOrderarrxz()
    {
        include_once "wxpay.php";
        global $_GPC, $_W;
        $oid = intval($_GPC["oid"]);
        $out_trade_no = rand(10000, 99999) . time() . rand(10000, 99999) . $oid;
        $orderinfo = pdo_get("yzzc_sun_xzorder", array("id" => $oid, "uniacid" => $_W["uniacid"]), array("total_money"));
        pdo_update("yzzc_sun_xzorder", array("out_trade_no" => $out_trade_no), array("id" => $oid));
        $total_fee = $orderinfo["total_money"];
        $appData = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]));
        $appid = $appData["appid"];
        $mch_id = $appData["mchid"];
        $key = $appData["wxkey"];
        $openid = $_GPC["openid"];
        $total_fee = $total_fee * 100;
        $body = "订单支付";
        $notify_url = $_W["siteroot"] . "addons/yzzc_sun/notify.php";
        $attach = $_W["uniacid"] . "@@@1@@@" . $oid;
        $wxpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $attach, $notify_url);
        $ret = $wxpay->pay();
        $this->return_msg(1, $ret);
    }
    function createPaySign($result)
    {
        global $_W;
        $appData = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]));
        $keys = $appData["wxkey"];
        $data = array("appId" => $result["appid"], "timeStamp" => (string) time(), "nonceStr" => $result["nonce_str"], "package" => "prepay_id=" . $result["prepay_id"], "signType" => "MD5");
        ksort($data, SORT_ASC);
        $stringA = '';
        foreach ($data as $key => $val) {
            $stringA .= "{$key}={$val}&";
        }
        $signTempStr = $stringA . "key=" . $keys;
        $signValue = strtoupper(md5($signTempStr));
        $data["paySign"] = $signValue;
        $data["prepay_id"] = $result["prepay_id"];
        return $data;
    }
    public function doPagePaysuccess()
    {
        global $_GPC, $_W;
        $oid = $_GPC["oid"];
        if ($oid) {
            $orderInfo = pdo_get("yzzc_sun_order", array("id" => $oid, "uniacid" => $_W["uniacid"]));
            $system = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), array("order_template_id"));
            if ($system["order_template_id"]) {
                $user = pdo_get("yzzc_sun_user", array("id" => $orderInfo["uid"]), array("openid"));
                $car = pdo_get("yzzc_sun_goods", array("id" => $orderInfo["cid"]));
                $data["keyword1"]["value"] = $_GPC["shopname"];
                $data["keyword2"]["value"] = $car["name"];
                $data["keyword3"]["value"] = $car["carnum"];
                $data["keyword4"]["value"] = date("Y年m月d日 H时i分s秒", $orderInfo["start_time"]);
                $res = $this->doPageSendtem($user["openid"], $system["order_template_id"], "yzzc_sun/pages/order/order", $_GPC["formId"], $data);
            }
            $this->return_msg(1, array("oid" => $oid, "sid" => $orderInfo["start_shop"], "res" => $res));
        }
    }
    function httpRequest($url, $data = null)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    public function doPageToken()
    {
        global $_W;
        $system = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), array("appid", "appsecret", "token_expires_in", "token"));
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $system["appid"] . "&secret=" . $system["appsecret"];
        $info = $this->httpRequest($url);
        $info = json_decode($info, true);
        pdo_update("yzzc_sun_system", array("token" => $info["access_token"], "token_expires_in" => time() + 7000), array("uniacid" => $_W["uniacid"]));
        $token = $info["access_token"];
        return $token;
    }
    public function doPageSendtem($openid, $template_id, $page, $form_id, $data)
    {
        $token = $this->doPageToken();
        $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $token;
        $info["touser"] = $openid;
        $info["template_id"] = $template_id;
        $info["page"] = $page;
        $info["form_id"] = $form_id;
        $info["data"] = $data;
        $res = $this->httpRequest($url, json_encode($info));
        return $res;
    }
    public function doPageQrpic()
    {
        global $_W, $_GPC;
        $set = pdo_get("yzzc_sun_system", array("uniacid" => $_W["uniacid"]), array("appid", "appsecret", "token_expires_in", "token"));
        $system["appid"] = $set["appid"];
        $system["appsecret"] = $set["appsecret"];
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $system["appid"] . "&secret=" . $system["appsecret"];
        $info = $this->httpRequest($url);
        $info = json_decode($info, true);
        $token = $info["access_token"];
        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $token;
        $data["scene"] = $_GPC["scene"];
        $data["page"] = $_GPC["page"];
        $data["width"] = 430;
        $jpg = $this->httpRequest($url, json_encode($data));
        if ($jpg) {
            $newpath = IA_ROOT . "/attachment/";
            $filename = time() . rand(1000, 9999) . ".jpg";
            $file = fopen($newpath . $filename, "w");
            fwrite($file, $jpg);
            fclose($file);
            @(require_once IA_ROOT . "/framework/function/file.func.php");
            @($filenames = $filename);
            @file_remote_upload($filenames);
            $this->return_msg(1, array("img" => $filename));
        } else {
            $this->return_msg(-1, array(), "小程序码错误");
        }
    }
    public function doPageDelimg()
    {
        global $_GPC;
        $file = IA_ROOT . "/attachment/" . $_GPC["img"];
        if (!unlink($file)) {
            echo "Error deleting {$file}";
        } else {
            echo "Deleted {$file}";
        }
    }
    private function curlPost($url, $postFields)
    {
        $postFields = json_encode($postFields);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $ret = curl_exec($ch);
        if (false == $ret) {
            $result = curl_error($ch);
        } else {
            $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if (200 != $rsp) {
                $result = "请求状态 " . $rsp . " " . curl_error($ch);
            } else {
                $result = $ret;
            }
        }
        curl_close($ch);
        return $result;
    }
    public function SendYtxSmsbl($sendid = '', $sms = array(), $params = '')
    {
        global $_W, $_GPC;
        $postArr = array("account" => $sms["ytx_apiaccount"], "password" => $sms["ytx_apipass"], "msg" => $sendid, "params" => $params, "report" => "true");
        $url = "http://smssh1.253.com/msg/variable/json";
        $result = $this->curlPost($url, $postArr);
        return $result;
    }
    public function SendYtxSms($msg, $sms = array(), $mobile = '')
    {
        $postArr = array("account" => $sms["api_account"], "password" => $sms["api_psw"], "msg" => urlencode($msg), "phone" => $mobile, "report" => "true");
        $url = "http://smssh1.253.com/msg/send/json";
        $result = $this->curlPost($url, $postArr);
        return $result;
    }
    public function doPageBranchCarlsit()
    {
        global $_W, $_GPC;
        $type = $_GPC["type"] ? $_GPC["type"] : 1;
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        if ($_GPC["sid"] > 0) {
            $where["sid"] = $_GPC["sid"];
        }
        $where["uniacid"] = $_W["uniacid"];
        $where["status"] = $type == 1 ? $type : 3;
        $where["is_del"] = 0;
        $res = pdo_getall("yzzc_sun_goods", $where, array(), '', array("status asc"), array($page, $length));
        $this->return_msg(1, $res);
    }
    public function doPageDoCar()
    {
        global $_W, $_GPC;
        $info = pdo_get("yzzc_sun_goods", array("id" => $_GPC["id"]));
        if ($_GPC["type"] == 1) {
            if ($info["status"] == 3) {
                $data["status"] = 1;
            } else {
                $this->return_msg(-1, array(), "当前车辆无法上架");
            }
        } else {
            if ($_GPC["type"] == 2) {
                if ($info["status"] == 1) {
                    $data["status"] = 3;
                } else {
                    $this->return_msg(-1, array(), "当前车辆无法下架");
                }
            } else {
                if ($_GPC["type"] == 3) {
                    if ($info["status"] == 1 || $info["status"] == 3) {
                        $data["is_del"] = 1;
                    } else {
                        $this->return_msg(-1, array(), "当前车辆无法删除");
                    }
                } else {
                }
            }
        }
        $res = pdo_update("yzzc_sun_goods", $data, array("id" => $_GPC["id"], "uniacid" => $_W["uniacid"]));
        if ($res) {
            $this->return_msg(1);
        } else {
            $this->return_msg(-1, array(), "error");
        }
    }
    public function doPageBranchOrder()
    {
        global $_GPC, $_W;
        $type = $_GPC["type"] ? $_GPC["type"] : 1;
        $page = $_GPC["page"] ? $_GPC["page"] : 1;
        $length = $_GPC["length"] ? $_GPC["length"] : 10;
        $where["type"] = $type;
        if ($_GPC["sid"] > 0) {
            $where["start_shop"] = $_GPC["sid"];
        }
        $where["uniacid"] = $_W["uniacid"];
        $where["display"] = 1;
        $where["status"] = $_GPC["status"];
        $res = pdo_getall("yzzc_sun_order", $where, array(), '', array("status asc"), array($page, $length));
        foreach ($res as $key => $val) {
            $res[$key]["carinfo"] = pdo_get("yzzc_sun_goods", array("id" => $val["cid"]));
            if ($res) {
                $info = pdo_get("yzzc_sun_branch", array("id" => $val["start_shop"]), array("id", "name", "province", "city", "area"));
                $info["province_name"] = $this->getcode($info["province"])["fullname"];
                $info["city_name"] = $this->getcode($info["city"])["fullname"];
                $info["area_name"] = $this->getcode($info["area"])["fullname"];
                $res[$key]["shop"] = $info;
                if ($val["iszx"] == 1) {
                    $xzorder = pdo_get("yzzc_sun_xzorder", array("uniacid" => $_W["uniacid"], "ordernum" => $val["ordernum"], "ispay" => 1));
                    $res[$key]["return_time"] = $xzorder["return_time"];
                    $res[$key]["end_time"] = $xzorder["end_time"];
                    $res[$key]["day"] = $val["day"] + $xzorder["day"];
                }
            }
        }
        $this->return_msg(1, $res, "success");
    }
    public function doPageReturnCar()
    {
        global $_GPC, $_W;
        $order = pdo_get("yzzc_sun_order", array("id" => $_GPC["id"], "uniacid" => $_W["uniacid"]));
        if ($order["iszx"] == 1) {
            $xzorder = pdo_get("yzzc_sun_xzorder", array("ordernum" => $order["ordernum"], "uniacid" => $_W["uniacid"]));
        }
        if ($order["status"] == 3) {
            $res = pdo_update("yzzc_sun_order", array("status" => 0, "return_time" => time()), array("id" => $_GPC["id"], "uniacid" => $_W["uniacid"]));
            if ($res) {
                $res1 = pdo_delete("yzzc_sun_ordertime", array("carnum" => $order["carnum"], "start_time" => $order["start_time"], "uniacid" => $_W["uniacid"], "end_time" => $order["end_time"]));
                if ($xzorder["ispay"] == 1) {
                    $res2 = pdo_delete("yzzc_sun_ordertime", array("carnum" => $order["carnum"], "start_time" => $xzorder["start_time"], "uniacid" => $_W["uniacid"], "end_time" => $xzorder["end_time"]));
                }
                $zlsz = pdo_get("yzzc_sun_order_set", array("uniacid" => $_W["uniacid"]), array("zlsz"));
                if ($zlsz["zlsz"] == 0) {
                    pdo_update("yzzc_sun_goods", array("status" => 1), array("uniacid" => $_W["uniacid"], "carnum" => $order["carnum"]));
                }
                include_once IA_ROOT . "/addons/" . $_W["current_module"]["name"] . "/inc/func/distribution.php";
                $distribution = new Distribution();
                $distribution->order_id = $_GPC["id"];
                $distribution->ordertype = $order["type"];
                $distribution->settlecommission();
                $this->return_msg(1, array(), "还车成功");
            } else {
                $this->return_msg(-1, array(), "还车失败！");
            }
        } else {
            $this->return_msg(-1, array(), "当前车辆无法还车！");
        }
    }

    /**
     * @return void
     * 检测分销商是否开启
     */
    public function doPagePlugin()
    {
        global $_W, $_GPC;
        $type = intval($_GPC["type"]);
        $uniacid = $_W["uniacid"];
        if ($type == 1) {
            if (pdo_tableexists("yzzc_sun_distribution_set")) {
                $set = pdo_get("yzzc_sun_distribution_set", array("uniacid" => $uniacid));
                $this->return_msg(1,$set);
                if ($set) {
                    if ($set["status"] > 0) {
                        echo json_encode($set);
                    } else {
                        echo 2;
                    }
                } else {
                    echo 2;
                }
            } else {
                echo 2;
            }
        } else {
            if ($type == 2) {
                if (pdo_tableexists("yzzc_sun_plugin_scoretask_system")) {
                    $system = pdo_get("yzzc_sun_plugin_scoretask_system", array("uniacid" => $_W["uniacid"]));
                    if ($system["is_show"] == 1) {
                        echo json_encode($system);
                    } else {
                        echo 2;
                    }
                } else {
                    echo 2;
                }
            } else {
                echo 2;
            }
        }
    }
    public function doPageTest()
    {
        global $_W, $_GPC;
        echo "aaaaaaaaaaaaa";
        include_once IA_ROOT . "/addons/" . $_W["current_module"]["name"] . "/inc/func/distribution.php";
        $distribution = new Distribution();
        $distribution->order_id = $_GPC["oid"];
        $distribution->money = 2000;
        $distribution->userid = "o3W0Y4xbxds5g0-bbf9qFzulgp6Q";
        $distribution->ordertype = 3;
        $distribution->computecommission();
    }
}